import 'package:flutter/material.dart';

class TextInputControllerTest extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: '',
      home: new Scaffold(
        appBar: new AppBar(
          title: new Text('input'),
        ),
        body: new EditWidget(),
      ),
    );
  }
}

class EditWidget extends StatefulWidget {
  @override
  EditState createState() {
    return EditState();
  }
}

class EditState extends State<EditWidget> {
  final TextEditingController _controller = new TextEditingController();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return new Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        new TextField(
          controller: _controller,
          decoration: new InputDecoration(
            hintText: 'Type something',
          ),
        ),
        new Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            new RaisedButton(
              onPressed: () {
                showDialog(
                    context: context,
                    child: new AlertDialog(
                      title: new Text('What you typed'),
                      content: new Text(_controller.text),
                    ));
              },
              child: new Text('弹窗显示内容'),
            ),
            new RaisedButton(
              onPressed: () {
                _controller.text = '这是手动设置的';
              },
              child: new Text('设置文本'),
            ),
          ],
        )
      ],
    );
  }
}
